;; test

(import '(persistent_heap PersistentHeap))
(import '(java.util ArrayList Collections))

(use 'clojure.contrib.seq-utils)
(use 'clojure.set)

(println "deduping 20000 nums")

(def orig
  (loop [ret (sorted-set) i 0]
    (if (< i 20000)
        (recur (conj ret (rand-int 2000000000)) (+ i 1))
        ret)))

(println "shuffling " (count (seq orig)) " nums")

(def orig (set (shuffle orig)))

(println "inserting into sorted set")

(time
(def a
  (loop [ret (sorted-set) i 0 col orig]
    (if (next col)
        (recur (conj ret (first col)) (+ i 1) (disj col (first col)))
        ret))))

(println "popping from front of sorted set")

(time
(def aa
  (loop [ret a]
    (if (next ret)
        (recur (disj ret (first ret)))
        ret))))

(println "heap insert")

(time
(def b
  (loop [ret (new PersistentHeap) i 0 col orig]
    (if (next col)
        (recur (.insert ret (first col) (first col)) (+ i 1) (disj col (first col)))
        ret))))

(println "heap pop")

(time
(def bb
  (loop [ret b]
    (if (not (.isEmpty ret))
        (recur (.deleteMin ret))
        ret))))
        

(println "making another set to test meld-like things")

(def aaa
  (loop [ret (sorted-set) i 0]
    (if (< i 2000000)
        (recur (conj ret (rand-int 2000000000)) (+ i 1))
        ret)))


(println "performing union of two sorted sets")
(time (def aaaa (union aaa a)))

(println "making another heap")
(def bbb
  (loop [ret (new PersistentHeap) i 0 col aaa]
    (if (next col)
        (recur (.insert ret (first col) (first col)) (+ i 1) (disj col (first col)))
        ret)))

(println "performing meld of two heaps")
(time (def bbbb (.meld bbb b)))

;(println "extract min from regular set")       
;(time
;(def cc
;  (loop [ret orig]
;    (if (next ret)
;        (recur (disj ret (apply min-key identity ret)))
;        ret))))
